<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>客户列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="__ADMIN__/css/font.css">
    <link rel="stylesheet" href="__ADMIN__/css/xadmin.css">
    <script type="text/javascript" src="__ADMIN__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ADMIN__/js/xadmin.js"></script>
    <script type="text/javascript" src="__ADMIN__/js/cookie.js"></script>
    <style>
        .layui-btn+.layui-btn{
            margin-left: 0;
        }
        .layui-table td, .layui-table th
        {
            min-width: 50px !important;
        }
        tr, td{font-size: 14px !important;}
    </style>
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a><cite>{$nav}</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-3" style="line-height:30px"></i></a>
</div>
<div class="x-body x-admin">

    <xblock>
        {if condition="$status eq 1"}
        <button style="float:left;" class="layui-btn" onclick="x_admin_show('录入客户','{:url('Client/add')}/status/{$status}',false,500,510)"><i class="layui-icon"></i>录入{switch name="$status"}{case value="3"}保A{/case}{case value="4"}签单{/case}{/switch}客户</button>
        {/if}
        {if condition="$status eq 1 && 1==2"}
        <button style="float:left; margin-left:10px;" class="layui-btn" onclick="x_admin_show('导入','{:url('client/import')}')">批量导入</button>
        {/if}
        {if condition="$status eq 3"}
        <a href="{:url('client/lst2')}" class="layui-btn layui-btn-primary">全部</a>
        <a href="{:url('client/lst2',['only_my'=>1])}" class="layui-btn layui-btn-primary">我的</a>
        {/if}
        {if condition="$status eq 4"}
        <a href="{:url('client/lst3')}" class="layui-btn layui-btn-primary">全部</a>
        <a href="{:url('client/lst3',['only_my'=>1])}" class="layui-btn layui-btn-primary">我的</a>
        <a href="{:url('client/lst3',['is_revoke'=>0])}" class="layui-btn layui-btn-primary">正常</a>
        <a href="{:url('client/lst3',['is_revoke'=>1])}" class="layui-btn layui-btn-primary">黄单</a>
        <div class="layui-input-inline layui-form">
            <select name="department_id" id="department_id"  lay-filter="department">
                <option value="">请选择部门</option>
                <option value="1">可赞</option>
                <option value="2">东创</option>
                <option value="3">雪鲸</option>
                <option value="4">星权</option>
            </select>
        </div>

        <div class="layui-input-inline layui-form" >
            <select name="admin" id="admin" lay-filter="admin">
                <option value="">请选择员工</option>
                <!--{volist name="admin_list" id="value"}-->
                <!--<option value="{$value.id}" {if condition="$value.id == $data.admin_id"} selected {/if}>-->
                <!--{$value.username}-->
                <!--</option>-->
                <!--{/volist}-->
            </select>
        </div>

        {/if}
        <div class="layui-card-body" style="padding-left: 0;float:left;padding-left:20px;padding-top:0;">
            <form class="layui-form layui-col-space5" action="/admin.php/client/{$lst}" method="get">

                {if condition="$status eq 4"}
                {include file="public/quick_date" /}
                {/if}
                <div class="layui-inline layui-show-xs-block">
                    <input style="width:260px;" type="text" name="keywords" id="search" value="{:input('keywords')}" placeholder="请输入客户姓名、赛事名称、联系方式" autocomplete="off" class="layui-input">
                    <!--<input type="text" name="admin_id" id="admin_id" value="{:input('admin_id')}">-->
                </div>
                <div class="layui-inline layui-show-xs-block">
                    <button class="layui-btn" id="search-btn"><i class="layui-icon"></i></button>
                </div>
            </form>
        </div>
        <span class="x-right" style="line-height:40px">共有数据：{$count}条</span>

    </xblock>
    <div class="layui-table-body layui-table-main" style="width: 100%;">
        <table class="layui-table layui-form">
            <thead>
            <th width="50">编号</th>
            <th>赛事名称</th>
            <th width="100">地区(市、县)</th>
            <th width="80">比赛时间</th>
            <th width="60">客户姓名</th>
            <th width="120">联系方式</th>
            <th width="60" style="text-align: center;">跟进情况</th>
            <th width="60">营销</th>
            <th width="80">录入时间</th>

            {if condition="$status eq 4"}
            <th width="80">签单时间</th>
            {/if}
            {if condition="$status eq 3"}
            <th width="80">保A时间</th>
            {/if}

            <th width="60">保护时间</th>

            <th {if condition="$client.status eq 3"}width="200"{else /}width="270"{/if} style="text-align: center;">操作</th>
            </thead>
            <tbody>
            {volist name="clientRes" id="client"}
            {php}
            /*if($client['status'] !== $status)
            continue;*/
            $client['scount'] = getCountByClientId($client['union_id'],'all','array');
            $client['phone'] = json_decode($client['phone'],true);
            if($client['status'] == 4  && ($client['xaid'] == session('uid','','admin') || session('group_id','','admin')  == 1))
            {
            $client['is_start'] = db('performance')->where('client_id',$client['id'])->count()?1:0;

            }
            {/php}
            <tr>
                <td>{$client.id}</td>
                <td>{switch name="$status"}{case value="1"}{$client['scount'][4]['text']}{$client['scount'][3]['text']}{$client['scount'][1]['text']}{/case}{case value="3"}{$client['scount'][4]['text']}{$client['scount'][3]['text']}{$client['scount'][1]['text']}{/case}{/switch}{$client.is_start==1?'<span class="layui-badge layui-bg-cyan">已启动</span> ':''}{$client.activity}</td>
                <td>{$client.address}</td>
                <td>{$client.activity_time}</td>
                <td>{$client.name}</td>
                <td>{if condition="$client['xaid'] eq $_SESSION['admin']['uid'] || $_SESSION['admin']['group_id'] eq 1"}
                    电话:{volist name="$client.phone" id="phone"}{$phone}{/volist}<br><p>微信:{$client.wx}</p>
                    {if condition="$client.wx_code"}<br><span class="wx-code-btn layui-font-blue" wx-code="{$client.wx_code}">微信二维码</span>{/if}
                    {else /}
                    电话:{volist name="$client.phone" id="phone"}{:hideContactNum($phone)}<br>{/volist}<p>微信:{:hideContactNum($client.wx)}</p>
                    {/if}</td>
                {switch name="$client.status11111" }
                {case value="1"}<td title="{$client.detail}" style="text-align: center;color:red;">洽谈中</td>{/case}
                {case value="2"}<td title="{$client.detail}" style="text-align: center;color:yellow;">意向</td>{/case}
                {case value="3"}<td title="{$client.detail}" style="text-align: center;color:green;">已被保A</td>{/case}
                {case value="4"}<td title="{$client.detail}" style="text-align: center;">合作</td>{/case}
                {default /}
                {/switch}
                <td title="{$client.detail}" style="text-align: center;">{:getFollowText($client.follow_status)}</td>
                <td>{:idToAdminname($client.xaid)}</td>
                <td>{$client.add_time|date="Y-m-d H:i:s",###}</td>
                {if condition="$status eq 4"}
                <td>{$client.qiandan_time|date="Y-m-d H:i:s",###}</td>
                {/if}
                {if condition="$status eq 3"}
                <td>{$client.baoA_time|date="Y-m-d H:i:s",###}</td>
                {/if}
                {if condition="$client.status eq 4 && $client.chat_check_status == -1"}
                <td>{:date('m-d H:i',$client.qiandan_time+86400)}前审核</td>
                {elseif condition="$client['end_time']>1"}
                <?php $end_time_y = ceil(($client['end_time'] - time()) / 86400);?>

                {if condition="$end_time_y gt 2"}
                <td>{$end_time_y}天</td>
                {else}
                <td  style="color:red;">{$end_time_y}天</td>
                {/if}
                {else}
                <td></td>

                {/if}
                <td class="td-manage" style="text-align: center;">
                    {if condition="$client['status'] eq 0"}
                    {// 客户池 }
                    <a title="关联" class="layui-btn layui-btn-normal layui-btn-xs" lay-filter="guanlian" lay-submit="" lay-id="{$client.id}" href="javascript:;">
                        <i class="layui-icon">&#xe669;关联</i>
                    </a>
                    {/if}
                    {if condition="$client['xaid'] eq $_SESSION['admin']['uid'] "}
                        {// 所属客户 }
                        {if condition="$client.status eq 1 "}
                        {// 录入状态-可保A （新）录入状态-可签单 去掉保A }
                        <!--<a title="保A" class="layui-btn layui-btn-normal layui-btn-xs" data2="&& $client['scount'][3]['count'] < 3  && $client['scount'][4]['count'] < 1  " lay-filter="baoA" lay-submit="" lay-id="{$client.id}" href="javascript:;">-->
                        <!--    <i class="layui-icon">&#xe770;保A</i>-->
                        <!--</a>-->
                        <a title="签单" class="layui-btn layui-btn-normal layui-btn-xs" data2="&& $client['scount'][4]['count'] < 1" onclick="x_admin_show('签单','{:url('Client/qian')}/id/{$client.id}',false,500,510)" href="javascript:;">
                            <i class="layui-icon">&#xe658;签单</i>
                        </a>
                        {elseif condition="$client.status eq 3 "}
                        {// 保A状态-可签单 }
                        <a title="签单" class="layui-btn layui-btn-normal layui-btn-xs" data2="&& $client['scount'][4]['count'] < 1" onclick="x_admin_show('签单','{:url('Client/qian')}/id/{$client.id}',false,500,510)" href="javascript:;">
                            <i class="layui-icon">&#xe658;签单</i>
                        </a>
                        {elseif condition="$client.status eq 4 && $client.is_revoke eq 0"}
                         {// 签单状态-可黄单 }
                        <a title="黄单" class="layui-btn layui-btn-warm layui-btn-xs" onclick="x_admin_show('黄单操作','{:url('Client/revokeClient')}/id/{$client.id}',false,500,510)" href="javascript:;">
                            黄单
                        </a>
                        {/if}
                        {if condition="$client.status neq 4 "}
                        <a title="回收" class="layui-btn layui-btn-normal layui-btn-xs" lay-filter="cancel" lay-submit="" lay-id="{$client.id}" href="javascript:;">
                            <i class="layui-icon">&#xe640;回收</i>
                        </a>
                        {/if}
                    {/if}
                    {if condition="$client['status'] eq 4"}
                    <!--<a title="活动详情" class="layui-btn layui-btn-normal layui-btn-xs" onclick="x_admin_show('活动详情','xq/id/{$client.id}')" href="javascript:;">-->
                    <!--    <i class="layui-icon">&#xe600;活动详情</i>-->
                    <!--</a>-->
                    {if condition="$client['xaid'] eq $_SESSION['admin']['uid'] || $_SESSION['admin']['group_id'] eq 1 "}
                    <a title="签单详情" class="layui-btn layui-btn-normal layui-btn-xs" onclick="x_admin_show('签单详情','{:url('Client/hetong')}/id/{$client.id}',false,500,510)" href="javascript:;">
                        签单详情
                    </a>
                    {/if}
                    <!-- <a title="回访" class="layui-btn layui-btn-normal layui-btn-xs"  href="javascript:;">
                        回访
                    </a> -->
                    {if condition=" $client.is_revoke eq 1 && $_SESSION['admin']['group_id'] eq 1 "}
                    <a title="回收" class="layui-btn layui-btn-warm layui-btn-xs" lay-filter="cancel" lay-submit="" lay-id="{$client.id}" href="javascript:;">
                        <i class="layui-icon">&#xe640;回收</i>
                    </a>
                    {/if}
                    {if condition="$_SESSION['admin']['group_id'] eq 1 || ($_SESSION['admin']['group_id'] eq 5 && in_array($client.xaid,$_SESSION['admin']['group_members']) ) "}
                    <a title="编辑" class="layui-btn layui-btn-normal layui-btn-xs" onclick="x_admin_show('编辑客户资料','{:url('Client/edit')}/id/{$client.id}',false,500,510)" href="javascript:;">
                        <i class="layui-icon">&#xe642;编辑</i>
                    </a>
                    {/if}
                    {else}
                    {if condition="$client['xaid'] eq $_SESSION['admin']['uid'] "}
                    <a title="续期" class="layui-btn layui-btn-normal layui-btn-xs" onclick="x_admin_show('续期','{:url('Client/xuqi')}/id/{$client.id}')" href="javascript:;">
                        <i class="layui-icon">&#xe669;续期</i>
                    </a>
                    {/if}
                    {if condition="$client['xaid'] eq $_SESSION['admin']['uid'] || $_SESSION['admin']['group_id'] eq 1"}
                    <a title="编辑" class="layui-btn layui-btn-normal layui-btn-xs" onclick="x_admin_show('编辑客户资料','{:url('Client/edit')}/id/{$client.id}'),500,510" href="javascript:;">
                        <i class="layui-icon">&#xe642;编辑</i>
                    </a>
                    {/if}


                    {/if}

                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
    </div>
    <div class="page">
        <div>
            {$clientRes->render()}
        </div>
    </div>
</div>

<script>
    layui.use(['form','layer','jquery','laydate'], function(){
        form = layui.form,
                layer = layui.layer
                ,$ = layui.jquery
                ,laydate = layui.laydate;

        laydate.render({
            elem: '#start_date'
        });
        laydate.render({
            elem: '#end_date'
        });

        form.on('select(department)', function(data){
            var department_id = data.value;

            $.ajax({
                type:'POST',
                dataType:'json',
                data:{department_id:department_id},
                url:"{:url('Client/lst3')}",
                success:function(o){
//                      console.log(o.data[0]['id']);
//                      return;
//                      $("#admin").html("");
                    $.each(o.data, function(key, val) {
//                          var option1 = $("<option>").val(val.areaId).text(val.fullname);
//                          <option value="{$value.id}" {if condition="$value.id == $data.admin_id"} selected {/if}>
                        var option = "<option value="+ o.data[key]['id'] +">" + o.data[key]['name'] + "</option>";
                        $("#admin").append(option);
                        form.render('select');
                    });
                    $("#admin").get(0).selectedIndex=0;
                }
            });
        });

        form.on('select(admin)', function(data){
            var admin_id = data.value;
//              alert(admin_id);
//              return;
//              var asd = "{:url('client/lst3',['admin_id'=>" + admin_id + "])}";
//              alert(asd);
//              return;

//              location.href = "{:url('client/lst3',['admin_id'=>" + admin_id + "])}";
            location.href = "/admin.php/client/lst3/admin_id/" + admin_id;

//              $.ajax({
//                  type:'POST',
//                  dataType:'json',
//                  data:{department_id:department_id},
//                  url:"{:url('Client/lst3')}",
//                  success:function(o){
////                      console.log(o.data[0]['id']);
////                      return;
////                      $("#admin").html("");
//                      $.each(o.data, function(key, val) {
////                          var option1 = $("<option>").val(val.areaId).text(val.fullname);
////                          <option value="{$value.id}" {if condition="$value.id == $data.admin_id"} selected {/if}>
//                          var option = "<option value="+ o.data[key]['id'] +">" + o.data[key]['name'] + "</option>";
//                          $("#admin").append(option);
//                          form.render('select');
//                      });
//                      $("#admin").get(0).selectedIndex=0;
//                  }
//              });

        });


        /*管理员开关*/
        form.on('switch(status)', function(data){
            var obj=data.elem;
            var id = data.elem.id;
            var status = data.value;
            $.ajax({
                type:'POST',
                dataType:'json',
                data:{status:status,id:id},
                url:"{:url('Admin/changeStatus')}",
                success:function(o){
                    if(o.icon == 1){
                        $(obj).attr('value',1);
                    }else{
                        $(obj).attr('value',0);
                    }
                    layer.msg(o.msg,{icon: o.icon,time:1000});
                }
            });
        });

        $('.wx-code-btn').click(function(){
            layer.open({
                type: 1,
                title: '扫一扫',
                area: ['310px', '360px'],
                content: '<img src="'+$(this).attr('wx-code')+'" style="width:305px;height:305px;" > '
            });
        })

        //监听提交
        form.on('submit(baoA)', function(data){
            var client_id = $(this).attr('lay-id');
            layer.confirm('确定将该客户进行保A吗？', {icon: 3, title:'保A操作'}, function(index){
                //do something
                $.ajax({
                    type:'POST',
                    dataType:'json',
                    data:{client_id:client_id},
                    url:"{:url('Client/baoA')}",
                    success:function(obj){
                        layer.msg(obj.msg, {icon: obj.icon,time: 2000},function(){
                            // 获得frame索引
                            // var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            // parent.layer.close(index);
                            // 可以对父窗口进行刷新 
                            //x_admin_father_reload();
                            location.reload();
                        });
                    }
                });
                layer.close(index);
            });
            return false;
        });
        form.on('submit(guanlian)', function(data){
            var client_id = $(this).attr('lay-id');
            layer.confirm('确定将该客户提取成自有客户吗？', {icon: 3, title:'关联操作'}, function(index){
                //do something
                $.ajax({
                    type:'POST',
                    dataType:'json',
                    data:{client_id:client_id},
                    url:"{:url('Client/guanlian')}",
                    success:function(obj){
                        if(obj.status == -2)
                        {
                            layer.open({
                                type: 2,
                                title: '申请继续关联客户',
                                shadeClose: false,
                                shade: false,
                                area: ['800px', '600px'],
                                content: '{:url('apply/guanlian')}/client_id/' + client_id
                        });
                        return;
                    }
                    layer.msg(obj.msg, {icon: obj.icon,time: 2000},function(){
                            // 获得frame索引
                            // var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            // parent.layer.close(index);
                            // 可以对父窗口进行刷新 
                            //x_admin_father_reload();
                            location.reload();
                        });
            }
        });
        layer.close(index);
    });
    return false;
    });
    form.on('submit(cancel)', function(data){
        var client_id = $(this).attr('lay-id');
        layer.confirm('确定将该客户进行回收吗？', {icon: 3, title:'回收操作'}, function(index){
            //do something
            $.ajax({
                type:'POST',
                dataType:'json',
                data:{client_id:client_id,{if condition="$lst eq 'lst2'"}type:2{elseif condition="$lst eq 'lst3'"}type:1{/if} },
                url:"{:url('Client/cancelClient')}",
                        success:function(obj){
                    layer.msg(obj.msg, {icon: obj.icon,time: 2000},function(){
                        // 获得frame索引
                        // var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        // parent.layer.close(index);
                        // 可以对父窗口进行刷新
                        //x_admin_father_reload();
                        location.reload();
                    });
                }
            });
            layer.close(index);
        });
        return false;
    });

    form.on('submit(revoke)', function(data){
        var client_id = $(this).attr('lay-id');

        return false;
    });

    });


</script>
</body>

</html>